package com.ruoyi.comment.controller;

import com.ruoyi.comment.domain.EvaluationOption;
import com.ruoyi.comment.service.IEvaluationOptionService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 管理测评题目的选项Controller
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/comment/option")
public class EvaluationOptionController extends BaseController
{
    @Autowired
    private IEvaluationOptionService evaluationOptionService;

    /**
     * 查询管理测评题目的选项列表
     */
    @PreAuthorize("@ss.hasPermi('comment:option:list')")
    @GetMapping("/list")
    public TableDataInfo list(EvaluationOption evaluationOption)
    {
        startPage();
        List<EvaluationOption> list = evaluationOptionService.selectEvaluationOptionList(evaluationOption);
        return getDataTable(list);
    }

    /**
     * 导出管理测评题目的选项列表
     */
    @PreAuthorize("@ss.hasPermi('comment:option:export')")
    @Log(title = "管理测评题目的选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EvaluationOption evaluationOption)
    {
        List<EvaluationOption> list = evaluationOptionService.selectEvaluationOptionList(evaluationOption);
        ExcelUtil<EvaluationOption> util = new ExcelUtil<EvaluationOption>(EvaluationOption.class);
        util.exportExcel(response, list, "管理测评题目的选项数据");
    }

    /**
     * 获取管理测评题目的选项详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:option:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(evaluationOptionService.selectEvaluationOptionById(id));
    }

    /**
     * 新增管理测评题目的选项
     */
    @PreAuthorize("@ss.hasPermi('comment:option:add')")
    @Log(title = "管理测评题目的选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvaluationOption evaluationOption)
    {
        return toAjax(evaluationOptionService.insertEvaluationOption(evaluationOption));
    }

    /**
     * 修改管理测评题目的选项
     */
    @PreAuthorize("@ss.hasPermi('comment:option:edit')")
    @Log(title = "管理测评题目的选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvaluationOption evaluationOption)
    {
        return toAjax(evaluationOptionService.updateEvaluationOption(evaluationOption));
    }

    /**
     * 删除管理测评题目的选项
     */
    @PreAuthorize("@ss.hasPermi('comment:option:remove')")
    @Log(title = "管理测评题目的选项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(evaluationOptionService.deleteEvaluationOptionByIds(ids));
    }
}
